package com.yanqu.road.server.manger.activity.curio.condition;

import com.yanqu.road.entity.config.beauty.BeautyInfo;
import com.yanqu.road.entity.player.UserBeauty;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.server.manger.config.BeautyMgr;

import java.util.List;
import java.util.Map;

/**
 * 结识特定职业的美女
 */
public class GetBeautyNumByOccupationCondition extends BaseCurioSpecialCondition {

    public GetBeautyNumByOccupationCondition(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean isCompleted(List<Integer> params) {
        int conditionNum = params.get(0);
        return getConditionValue(params) >= conditionNum;
    }

    @Override
    public long getConditionValue(List<Integer> params) {
        int occupation = 0;
        if(params.size() > 1){
            occupation = params.get(1);
        }
        int num = 0;
        Map<Integer, UserBeauty> beautyMap = player.getModule(BeautyModule.class).getBeautyMap();
        for (Map.Entry<Integer, UserBeauty> entry : beautyMap.entrySet()) {
            UserBeauty beauty = entry.getValue();
            BeautyInfo beautyInfo = BeautyMgr.getBeautyInfo(beauty.getBeautyId());
            if(beautyInfo == null){
                continue;
            }
            if(occupation == 0 || beautyInfo.getOccupation() == occupation){
                num++;
            }
        }
        return num;
    }
}
